package com.oguzhan.blog.scheduloor;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class RandomJobGenerator {

	public static List<Job> getJobList() {
		return getJobList(10);
	}
	
	public static List<Job> getJobList(int size) {
		List<Job> jobs = new ArrayList<Job>(size);
		
		for (int i = 0; i < size; i++) {
			jobs.add(i, getJob());
		}
		
		return jobs;
	}
	
	public static Job getJob() {
		Runnable ctx = new Runnable() {
			
			private Date timestamp = new Date();
			private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); 
			
			@Override
			public void run() {
				System.out.println(toString() + " worked at " + dateFormat.format(new Date()));
			}
			
			@Override
			public String toString() {
				return dateFormat.format(this.timestamp);
			}
			
		};
		
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.SECOND, (int)(Math.random()*60));
		calendar.add(Calendar.MINUTE, (int)(Math.random()*60));
		calendar.add(Calendar.HOUR, (int)(Math.random()*12));
		
		return new Job(ctx, calendar.getTime(), "TEST");
	}
	
	public static Job getJobToRunIn3Sec() {
		Runnable ctx = new Runnable() {
			
			private Date timestamp = new Date();
			private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); 
			
			@Override
			public void run() {
				System.out.println(toString() + " worked at " + dateFormat.format(new Date()));
			}
			
			@Override
			public String toString() {
				return dateFormat.format(this.timestamp);
			}
			
		};
		
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.SECOND, 3);
		
		return new Job(ctx, calendar.getTime(), "TEST");
	}
}
